package com.devstringx.pmt.web.common;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.devstringx.pmt.form.common.UserRegistrationForm;
import com.devstringx.pmt.service.common.CommonService;

@Controller
public class CommonController {

	@Autowired
	CommonService commonService;
	
	@RequestMapping(value="registerUser.htm")
	public ModelAndView getRegisterPage(@ModelAttribute("registerUser") @Valid UserRegistrationForm userRegistrationForm,BindingResult result){
		ModelAndView  mav=new  ModelAndView();
    
		if(result.hasErrors()){
              mav.setViewName("index");		  
		  }else {
			  mav.setViewName("registerSucess");

			   commonService.registerNewUser(userRegistrationForm);
			 
		  }
		return mav;
	}
	
	
}
